/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProfesorUI.java
 *
 * Created on Mar 17, 2010, 3:28:43 PM
 */

package edu.fca.ui;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
import edu.fca.beans.AcreditacionBean;
import edu.fca.beans.AlumnoBean;
import edu.fca.beans.CalendarioBean;
import edu.fca.beans.ProfesorBean;
import edu.fca.ui.exceptions.InvalidCodeException;
import edu.fca.ui.exceptions.InvalidLastNameException;
import edu.fca.ui.exceptions.InvalidNameException;
import edu.fca.ui.search.SearchAlumnoUI;
import edu.fca.ui.tools.AlertManager;
import edu.fca.ui.tools.ComponentManager;
import edu.fca.ui.tools.Validations;
import java.sql.Date;
import java.util.ArrayList;
import logic.services.AlumnoServices;
import logic.services.CalendarioServices;
import logic.services.ProfesorServices;

/**
 *
 * @author Romms
 */
public class AlumnoUI extends javax.swing.JInternalFrame {

    /** Creates new form ProfesorUI */
    private AlumnoBean alumnoBean;
    
    private ProfesorBean profesorBean;
    private CalendarioBean calendarioBean;
    private AcreditacionBean acreditacionBean;

    private ArrayList <CalendarioBean> calendariosBean;
    private ArrayList <ProfesorBean> profesorsBean;

    private ArrayList<String> codigosProfesores;

    public AlumnoUI() {
        alumnoBean = new AlumnoBean();
        this.codigosProfesores= new ArrayList();
        profesorsBean = ProfesorServices.getInstance().getProfesores();
        calendariosBean=CalendarioServices.getInstance().getAllValidCalendars();
        
        initComponents();
        System.out.println(this.txtApllM.getParent());
        ComponentManager.enableDisableComponentesIn(this.getContentPane().getComponents(), false);
        startMenuBar();
        fillValidCalendars();
    }

    private void fillValidCalendars(){        
        for(int i=0;i<calendariosBean.size();i++){
            if(!dateExists(calendariosBean.get(i).getFecha().toString())){
                this.cmbFecha.addItem(calendariosBean.get(i).getFecha());
            }
        }
    }

    private void fillHours(String date){
        for(int i=0;i<calendariosBean.size();i++){
            if(calendariosBean.get(i).getFecha().toString().equalsIgnoreCase(date)){
                if(!hourExists(calendariosBean.get(i).getHora().toString())){
                    this.cmbHora.addItem(calendariosBean.get(i).getHora());
                }
            }
        }
    }

    private boolean hourExists(String hour){
        for(int i=0;i<this.cmbHora.getItemCount();i++){
            if(this.cmbHora.getItemAt(i).toString().equalsIgnoreCase(hour))
                return true;
        }
        return false;
    }

    private boolean dateExists(String date){
        for(int i=0;i<this.cmbFecha.getItemCount();i++){
            if(this.cmbFecha.getItemAt(i).toString().equalsIgnoreCase(date))
                return true;
        }
        return false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tlbMenuBarra = new javax.swing.JToolBar();
        btnNuevo = new javax.swing.JButton();
        btnEditar = new javax.swing.JButton();
        btnBorrar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnAcept = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        cmbFecha = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        cmbHora = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        cmbProfesor = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        txtLic = new javax.swing.JTextField();
        txtApllM = new javax.swing.JTextField();
        txtApllP = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();
        txtMatricula = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Alumno");

        tlbMenuBarra.setRollover(true);

        btnNuevo.setText("Nuevo");
        btnNuevo.setFocusable(false);
        btnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        tlbMenuBarra.add(btnNuevo);

        btnEditar.setText("Editar");
        btnEditar.setFocusable(false);
        btnEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tlbMenuBarra.add(btnEditar);

        btnBorrar.setText("Borrar");
        btnBorrar.setFocusable(false);
        btnBorrar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnBorrar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tlbMenuBarra.add(btnBorrar);

        btnBuscar.setText("Buscar");
        btnBuscar.setFocusable(false);
        btnBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
        tlbMenuBarra.add(btnBuscar);

        btnCancelar.setText("Cancelar");
        btnCancelar.setFocusable(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        tlbMenuBarra.add(btnCancelar);

        btnAceptar.setText("Aceptar");
        btnAceptar.setFocusable(false);
        btnAceptar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAceptar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        tlbMenuBarra.add(btnAceptar);

        btnCancel.setText("Cancelar");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnAcept.setText("Aceptar");
        btnAcept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Calendario"));

        jLabel6.setText("Fecha:");

        cmbFecha.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbFechaItemStateChanged(evt);
            }
        });

        jLabel7.setText("Hora:");

        cmbHora.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbHoraItemStateChanged(evt);
            }
        });

        jLabel8.setText("Profesor:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addGap(50, 50, 50)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cmbProfesor, 0, 151, Short.MAX_VALUE)
                    .addComponent(cmbHora, javax.swing.GroupLayout.Alignment.LEADING, 0, 151, Short.MAX_VALUE)
                    .addComponent(cmbFecha, javax.swing.GroupLayout.Alignment.LEADING, 0, 151, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cmbFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(cmbHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(cmbProfesor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Alumno"));

        txtMatricula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtMatriculaFocusLost(evt);
            }
        });
        txtMatricula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtMatriculaKeyReleased(evt);
            }
        });

        jLabel2.setText("Nombre:");

        jLabel3.setText("Apellido Paterno:");

        jLabel1.setText("Matrícula");

        jLabel5.setText("Licenciatura:");

        jLabel4.setText("Apellido Materno:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(41, 41, 41)
                        .addComponent(txtLic, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtMatricula, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtApllP, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                            .addComponent(txtApllM, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtApllP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtApllM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtLic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btnCancel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnAcept))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tlbMenuBarra, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tlbMenuBarra, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAcept)
                    .addComponent(btnCancel))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        if(this.btnAceptar.isEnabled()){
            int answer=AlertManager.showOkCancelAlert("Registro sin guardar.", "Actualmente está editando un registro, " +
                    "¿Desea borrar la información?");
            if(answer!=0) return;
        }

        ComponentManager.cleanAllInTextFieldsIn(this.getContentPane().getComponents());
        ComponentManager.enableDisableComponentesIn(this.getContentPane().getComponents(), true);
        this.btnAceptar.setEnabled(true);
        this.btnCancelar.setEnabled(true);

        this.btnEditar.setEnabled(false);
        this.btnBorrar.setEnabled(false);
        this.btnBuscar.setEnabled(false);

        this.txtMatricula.requestFocus();
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void fillAlumnoBean(){
        this.alumnoBean.setMatricula(this.txtMatricula.getText());
        this.alumnoBean.setNombre(this.txtNombre.getText());
        this.alumnoBean.setApellidoP(this.txtApllP.getText());
        this.alumnoBean.setApellidoM(this.txtApllM.getText());
        this.alumnoBean.setLic(this.txtLic.getText());
    }

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        try {
            validateData();
            fillAlumnoBean();
            AlumnoServices.getInstance().addAlumno(alumnoBean);

            ComponentManager.cleanAllInTextFieldsIn(this.getContentPane().getComponents());
            ComponentManager.enableDisableComponentesIn(this.getContentPane().getComponents(), false);
            startMenuBar();

        }catch (MySQLIntegrityConstraintViolationException ex) {
            AlertManager.showAlert("Matrícula inválida.", "La matrícula "+this.txtMatricula.getText()+" ya existe.");
            this.txtMatricula.select(0, this.txtMatricula.getText().length());
        }catch (InvalidLastNameException ex) {
            AlertManager.showAlert("Apellido paterno inválido.", ex.getExceptionMessage());
        } catch (InvalidNameException ex) {
            AlertManager.showAlert("Nombre inválido.", ex.getExceptionMessage());
        } catch (InvalidCodeException ex) {
            AlertManager.showAlert("Código inválido", ex.getExceptionMessage());
        }
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        ComponentManager.cleanAllInTextFieldsIn(this.getContentPane().getComponents());
        ComponentManager.enableDisableComponentesIn(this.getContentPane().getComponents(), false);
        startMenuBar();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void txtMatriculaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMatriculaFocusLost

    }//GEN-LAST:event_txtMatriculaFocusLost

    private void btnAceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptActionPerformed
        this.btnAceptarActionPerformed(evt);
    }//GEN-LAST:event_btnAceptActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        this.btnCancelarActionPerformed(evt);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void txtMatriculaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMatriculaKeyReleased
        
    }//GEN-LAST:event_txtMatriculaKeyReleased

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        SearchAlumnoUI searchAlumnoUI=new SearchAlumnoUI(null, true);
        searchAlumnoUI.setVisible(true);
        searchAlumnoUI.dispose();
        this.alumnoBean=searchAlumnoUI.getSelectedAlumno();
        
        fillProfesorFields(alumnoBean);
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void cmbFechaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbFechaItemStateChanged
        fillHours(this.cmbFecha.getSelectedItem().toString());
    }//GEN-LAST:event_cmbFechaItemStateChanged

    private void cmbHoraItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbHoraItemStateChanged
        this.cmbProfesor.removeAllItems();
        this.codigosProfesores.clear();

        for(int i=0;i<calendariosBean.size();i++){
            if(calendariosBean.get(i).getFecha().toString().equalsIgnoreCase(this.cmbFecha.getSelectedItem().toString())){
                if(calendariosBean.get(i).getHora().toString().equals(this.cmbHora.getSelectedItem().toString())){
                    this.codigosProfesores.add(calendariosBean.get(i).getProfesorCodigo());
                }
            }
        }

        for(int i=0;i<codigosProfesores.size();i++){
            for(int profIndex=0;profIndex<profesorsBean.size();profIndex++){
               if(codigosProfesores.get(i).toString().equals(profesorsBean.get(profIndex).getCodigo())){
                   this.cmbProfesor.addItem(profesorsBean.get(profIndex).getNombre() + " " + profesorsBean.get(profIndex).getApellidoP());
               }
            }
        }
        
    }//GEN-LAST:event_cmbHoraItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAcept;
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnBorrar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JComboBox cmbFecha;
    private javax.swing.JComboBox cmbHora;
    private javax.swing.JComboBox cmbProfesor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JToolBar tlbMenuBarra;
    private javax.swing.JTextField txtApllM;
    private javax.swing.JTextField txtApllP;
    private javax.swing.JTextField txtLic;
    private javax.swing.JTextField txtMatricula;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables

    private void startMenuBar(){
        btnNuevo.setEnabled(true);
        btnBuscar.setEnabled(true);

        btnEditar.setEnabled(false);
        btnBorrar.setEnabled(false);
        btnCancelar.setEnabled(false);
        btnAceptar.setEnabled(false);
    }

    private void validateData() throws InvalidCodeException, InvalidNameException, InvalidLastNameException{
        if(!Validations.textFieldSizeEqual(this.txtMatricula, 8)){
            this.txtMatricula.requestFocus();
            this.txtMatricula.select(0, this.txtMatricula.getText().length());
            throw new InvalidCodeException("Mátrícula inválida, matrícula es de 8 caracteres.");
        }

        if(this.txtNombre.getText().isEmpty()){
            this.txtNombre.requestFocus();
            throw new InvalidNameException("El nombre no puede ser vacío.");
        }

        if(this.txtApllP.getText().isEmpty()){
            this.txtApllP.requestFocus();
            throw new InvalidLastNameException("El apellido paterno no puede ser vacío.");
        }
    }

    private void fillProfesorFields(AlumnoBean alumnoBean){
        this.txtMatricula.setText(alumnoBean.getMatricula());
        this.txtNombre.setText(alumnoBean.getNombre());
        this.txtApllP.setText(alumnoBean.getApellidoP());
        this.txtApllM.setText(alumnoBean.getApellidoM());
    }

}

